package itman.spcloud.controller;

import itman.spcloud.po.CommonResult;
import itman.spcloud.po.Food;
import itman.spcloud.service.FoodService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin("*")
@RestController
@RequestMapping("/FoodController")
@RefreshScope
public class FoodController {

    @Autowired
    private FoodService foodService;

    @GetMapping("/listFoodByBusinessId/{businessId}")
    public CommonResult<List> listFoodByBusinessId(@PathVariable("businessId") Integer businessId) throws Exception{
        List<Food> list = foodService.listFoodByBusinessId(businessId);
        return new CommonResult(200,"success",list);
    }

    @GetMapping("/getFoodById/{foodId}")
    public CommonResult<Food> getFoodById(@PathVariable("foodId") Integer foodId) throws Exception{
        Food param = new Food();
        param.setFoodId(foodId);
        Food food = foodService.getFoodById(param.getFoodId());
        return new CommonResult(200,"success",food);
    }
}